#include "Anx_crc.h"

#include "crc.h"

#define Htonl16(x)(((x)&0xff00) | (((x) &0x00ff) << 8))

#define Htonl(x) ((((x) & (uint32_t)0x000000ffUL) << 24) | \
                  (((x) & (uint32_t)0x0000ff00UL) <<  8) | \
                  (((x) & (uint32_t)0x00ff0000UL) >>  8) | \
                  (((x) & (uint32_t)0xff000000UL) >> 24))


uint32_t Anx_HTN_CRC_Calculate(uint32_t pBuffer[], uint32_t BufferLength)
{
    uint32_t index;      /* CRC input data buffer index */
    uint32_t temp = 0U;  /* CRC output (read from hcrc->Instance->DR register) */

    /* Change CRC peripheral state */
    hcrc.State = HAL_CRC_STATE_BUSY;

    /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
    *  written in hcrc->Instance->DR) */
    __HAL_CRC_DR_RESET(&hcrc);

    /* Enter 32-bit input data to the CRC calculator */
    for (index = 0U; index < BufferLength; index++)
    {
        hcrc.Instance->DR = Htonl(pBuffer[index]);
    }
    temp = hcrc.Instance->DR;

    /* Change CRC peripheral state */
    hcrc.State = HAL_CRC_STATE_READY;

    /* Return the CRC computed value */
    return temp;
}
/* USER CODE END 0 */

/*----------------------------------END---------------------------------------*/

